package com.vogue.supplymall.admin.business.config;

import com.vogue.supplymall.account.shiro.filter.AdminAuthenticationFiler;
import com.vogue.supplymall.common.config.JacksonConvert;
import com.vogue.supplymall.common.domain.tool.MessageSourceUtils;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.List;

/**
 * The type Admin business config.
 *
 * @aouthor: zhangliang
 * @date: Create in 2018-04-24
 */
@Configuration
@ComponentScan(value = {"com.vogue.supplymall.common.domain.tool",
        "com.vogue.supplymall.account.controller",
        "com.vogue.supplymall.account.domain",
        "com.vogue.supplymall.account.shiro",
        "com.vogue.supplymall.shop.domain",
        "com.vogue.supplymall.shop.common",
        "com.vogue.supplymall.order.domain",
        "com.vogue.supplymall.order.common",
        "com.vogue.supplymall.entmanagement.domain",
        "com.vogue.supplymall.upload.domain",
        "com.vogue.supplymall.cross.domain",
        "com.vogue.supplymall.match.domain",
        "com.vogue.supplymall.payment.api"})
@MapperScan({"com.vogue.supplymall.account.domain.mapper",
        "com.vogue.supplymall.match.domain.mapper",
        "com.vogue.supplymall.shop.domain.mapper",
        "com.vogue.supplymall.order.domain.mapper",
        "com.vogue.supplymall.entmanagement.domain.mapper",
        "com.vogue.supplymall.cross.domain.mapper",
        "com.vogue.supplymall.admin.business.domain.mapper"})
@ImportResource(locations = {"classpath:admin-business-context.xml", "classpath:base-context.xml"})
public class AdminBusinessConfig extends WebMvcConfigurerAdapter {

    @Bean
    public FilterRegistrationBean regAuth(AdminAuthenticationFiler filter) {
        FilterRegistrationBean registration = new FilterRegistrationBean(filter);
        registration.setEnabled(false);
        return registration;
    }

    @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        JacksonConvert.convert(converters);
    }

    @Bean(name = "messageSourceUtils")
    public MessageSourceUtils messageSourceUtils() {
        return new MessageSourceUtils("i18n/adminAccountmessages");
    }

    @Bean(name = DispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME)
    public CommonsMultipartResolver multipartResolver() {
        CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
        // 50M
        multipartResolver.setMaxUploadSize(52428800);
        return multipartResolver;
    }

}
